const AdSpace = require("../models/AdSpace");
exports.addAdSpace = async function (data) {
  const ins = await AdSpace.create(data);
  return ins.toJSON()
};

exports.deleteAdSpace = async function (id) {
    await AdSpace.destroy({                  
        where:{
            id
        }
    })
};

exports.updateAdSpace = async function (id,data) {
    await AdSpace.update(data,{
        where:{
            id
        }
    })
};


//分页查询
exports.findAdSpaces = async function () {

    const result = await AdSpace.findAndCountAll();
    return {
      total: result.count,
      list: JSON.parse(JSON.stringify(result.rows)),
    };
  };
  
  exports.findAdSpaceById = async function (id) {
    const result = await AdSpace.findByPk(id);
    return result.toJSON();
  };
  exports.findAdSpaceByType = async function (type) {
    const result = await AdSpace.findOne({
      where:{
        type
      }
    })
    return result.toJSON();
  };
